package org.example.likou150.section;

import java.util.Arrays;

// https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/description/?envType=study-plan-v2&envId=top-interview-150
public class FindMinArrowShots {
    public static void main(String[] args) {

    }

    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points,(a, b)-> a[0]-b[0]);
        if(points.length==0) return 0;
        int minCount=1;
        int left=points[0][0];
        int right=points[0][1];
        for (int i = 1; i < points.length; i++) {
            int[] nums=points[i];
            if((nums[0]>=left && nums[0]<=right)||(nums[1]>=left && nums[1]<=right)){
                left=Math.max(left, nums[0]);
                right=Math.min(right, nums[1]);
            }else {
                left=nums[0];
                right=nums[1];
                minCount++;
            }
        }
        return minCount;
    }
}
